#    pythonequations is a collection of equations expressed as Python classes
#    Copyright (C) 2008 James R. Phillips
#    2548 Vera Cruz Drive
#    Birmingham, AL 35235 USA
#    email: zunzun@zunzun.com
#
#    License: BSD-style (see LICENSE.txt in main source directory)
#    Version info: $Id: YieldDensity.py 274 2010-09-29 13:16:14Z zunzun.com $

import pythonequations, pythonequations.EquationBaseClasses, pythonequations.ExtraCodeForEquationBaseClasses
import numpy
numpy.seterr(all = 'raise') # numpy raises warnings, convert to exceptions to trap them


class Holliday2D(pythonequations.EquationBaseClasses.Equation2D):
    RequiresAutoGeneratedGrowthAndDecayForms = True
    RequiresAutoGeneratedOffsetForm = False
    RequiresAutoGeneratedReciprocalForm = False
    RequiresAutoGeneratedInverseForms = False
    _name = "Holliday"
    _HTML = "y = 1.0 / (a + bx + cx<SUP>2</SUP>)"
    coefficientDesignatorTuple = ("a", "b", "c")
    function_cpp_code = 'temp = 1.0 / (coeff[0] + coeff[1] * _id[_cwo[0]+i] + coeff[2] * _id[_cwo[1]+i]);'


    def CreateCacheGenerationList(self):
        self.CacheGenerationList = []
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_X(NameOrValueFlag=1),  []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_PowX(NameOrValueFlag=1, args=[2.0]), [2.0]])

    def SpecificCodeCPP(self):
        s = "\ttemp = 1.0 / (a + b * x_in + c * x_in * x_in);\n"
        return s



class ExtendedHolliday2D(pythonequations.EquationBaseClasses.Equation2D):
    RequiresAutoGeneratedGrowthAndDecayForms = True
    RequiresAutoGeneratedOffsetForm = True
    RequiresAutoGeneratedReciprocalForm = False
    RequiresAutoGeneratedInverseForms = False
    _name = "Extended Holliday"
    _HTML = "y = a / (a + bx + cx<SUP>2</SUP>)"
    coefficientDesignatorTuple = ("a", "b", "c")
    function_cpp_code = 'temp = coeff[0] / (coeff[0] + coeff[1] * _id[_cwo[0]+i] + coeff[2] * _id[_cwo[1]+i]);'


    def CreateCacheGenerationList(self):
        self.CacheGenerationList = []
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_X(NameOrValueFlag=1),  []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_PowX(NameOrValueFlag=1, args=[2.0]), [2.0]])

    def SpecificCodeCPP(self):
        s = "\ttemp = a / (a + b * x_in + c * x_in * x_in);\n"
        return s



class Bleasdale2D(pythonequations.EquationBaseClasses.Equation2D):
    RequiresAutoGeneratedGrowthAndDecayForms = True
    RequiresAutoGeneratedOffsetForm = False
    RequiresAutoGeneratedReciprocalForm = False
    RequiresAutoGeneratedInverseForms = False
    _name = "Bleasdale"
    _HTML = "y = 1.0 / (a + bx)<SUP>(-1.0/c)</SUP>"
    coefficientDesignatorTuple = ("a", "b", "c")
    function_cpp_code = 'temp = 1.0 / pow(coeff[0] + coeff[1] * _id[_cwo[1]+i], -1.0 / coeff[2]);'


    def CreateCacheGenerationList(self):
        self.CacheGenerationList = []
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_X(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])

    def SpecificCodeCPP(self):
        s = "\ttemp = 1.0 / pow((a + b*x_in), (-1.0/c));\n"
        return s



class InverseBleasdale2D(pythonequations.EquationBaseClasses.Equation2D):
    RequiresAutoGeneratedGrowthAndDecayForms = True
    RequiresAutoGeneratedOffsetForm = True
    RequiresAutoGeneratedReciprocalForm = False
    RequiresAutoGeneratedInverseForms = False
    _name = "Inverse Bleasdale"
    _HTML = "y = x / (a + bx)<SUP>(-1.0/c)</SUP>"
    coefficientDesignatorTuple = ("a", "b", "c")
    function_cpp_code = 'temp = _id[_cwo[1]+i] / pow(coeff[0] + coeff[1] * _id[_cwo[1]+i], -1.0 / coeff[2]);'


    def CreateCacheGenerationList(self):
        self.CacheGenerationList = []
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_X(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])

    def SpecificCodeCPP(self):
        s = "\ttemp = x_in / pow((a + b*x_in), (-1.0/c));\n"
        return s



class Harris2D(pythonequations.EquationBaseClasses.Equation2D):
    RequiresAutoGeneratedGrowthAndDecayForms = True
    RequiresAutoGeneratedOffsetForm = False
    RequiresAutoGeneratedReciprocalForm = False
    RequiresAutoGeneratedInverseForms = False
    _name = "Harris"
    _HTML = "y = 1.0 / (a + bx<SUP>c</SUP>)"
    coefficientDesignatorTuple = ("a", "b", "c")
    function_cpp_code = 'temp = 1.0 / (coeff[0] + coeff[1] * pow(_id[_cwo[1]+i], coeff[2]));'


    def CreateCacheGenerationList(self):
        self.CacheGenerationList = []
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_X(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])

    def SpecificCodeCPP(self):
        s = "\ttemp = 1.0 / (a + b*pow(x_in, c));\n"
        return s



class InverseHarris2D(pythonequations.EquationBaseClasses.Equation2D):
    RequiresAutoGeneratedGrowthAndDecayForms = True
    RequiresAutoGeneratedOffsetForm = True
    RequiresAutoGeneratedReciprocalForm = False
    RequiresAutoGeneratedInverseForms = False
    _name = "InverseHarris"
    _HTML = "y = x / (a + bx<SUP>c</SUP>)"
    coefficientDesignatorTuple = ("a", "b", "c")
    function_cpp_code = 'temp = _id[_cwo[1]+i] / (coeff[0] + coeff[1] * pow(_id[_cwo[1]+i], coeff[2]));'


    def CreateCacheGenerationList(self):
        self.CacheGenerationList = []
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_X(NameOrValueFlag=1), []])
        self.CacheGenerationList.append([pythonequations.ExtraCodeForEquationBaseClasses.CG_Ones(NameOrValueFlag=1), []])

    def SpecificCodeCPP(self):
        s = "\ttemp = x_in / (a + b*pow(x_in, c));\n"
        return s
